package com.landscope.issue.service.applet;

import com.landscope.issue.controller.base.ResponseResult;
import com.landscope.issue.controller.wx.dto.AppletMessageListDto;
import com.landscope.issue.controller.wx.param.AppletMessageListParam;
import com.landscope.issue.mapper.MessageMapper;
import com.landscope.issue.utils.TokenUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
@Slf4j
public class ApiAppletMessageService {

    @Resource
    private MessageMapper messageMapper;

    public ResponseResult<AppletMessageListDto> list(AppletMessageListParam param) {
        // 验证项目权限
        TokenUtil.verifyAuthority(param.getAccessToken(), param.getProjectCode());

        AppletMessageListDto dto = new AppletMessageListDto();

        // 查找消息
        List<AppletMessageListDto.MessageItem> versionList = messageMapper.findAppletMessageListByType(1,param.getProjectCode());
        List<AppletMessageListDto.MessageItem> staList = messageMapper.findAppletMessageListByType(2,param.getProjectCode());
        dto.setStaList(staList);
        dto.setVersionList(versionList);

        return new ResponseResult<AppletMessageListDto>().success().setData(dto);
    }

    public ResponseResult read(AppletMessageListParam param) {
        // 验证项目权限
        TokenUtil.verifyAuthority(param.getAccessToken(), param.getProjectCode());
        messageMapper.readByProjectCode(param.getProjectCode());
        return new ResponseResult<AppletMessageListDto>().success();
    }
}
